<template>
	<div>
		<van-nav-bar title="登录" left-text="返回" left-arrow v-goBack />

		<van-form @submit="onSubmit">
			<van-field v-model="formData.name" name="name" label="用户名" placeholder="用户名" :rules="[{ required: true, message: '请填写用户名' }]" />
			<van-field v-model="formData.pwd" type="password" name="pwd" label="密码" placeholder="密码" :rules="[{ required: true, message: '请填写密码' }]" />
			<div style="margin: 16px;">
				<van-button round block type="info" native-type="submit">提交</van-button>
			</div>
		</van-form>
	</div>
</template>

<script>
	import {login} from "api/login.js"
	export default{
		data(){
			return{
				formData:{
					name:"",
					pwd:""
				}
			}
		},
		methods:{
			async onSubmit(val){
				let res = await login(val)
				
				if(res.data.code === 1000){
					this.$toast.success(res.data.msg);
					localStorage.setItem("token",res.data.token)
					this.$router.push("/user")
				}else{
					this.$toast.fail(res.data.msg);
				}
			}
		}
	}
</script>

<style>
</style>
